package com.kongmou.springTransaction.services.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kongmou.springTransaction.dao.PersonRepository;
import com.kongmou.springTransaction.domain.Person;
import com.kongmou.springTransaction.services.PersonService;

@Service
public class PersonServiceImpl implements PersonService {

	@Resource
	private PersonRepository personRepository;

	@Override
	@Transactional(rollbackFor={IllegalArgumentException.class})
	public Person savePersonWithRollBack(Person person) {
		Person p = personRepository.save(person);
		if (person.getName().equals("汪云飞")) {
			throw new IllegalArgumentException("汪云飞数据已经存在事物回滚");

		}

		return p;
	}

	@Override
	@Transactional(noRollbackFor = {IllegalArgumentException.class})
	public Person savePersonWithoutRollBack(Person person) {
		Person p = personRepository.save(person);
		if (person.getName().equals("汪云飞")) {
			throw new IllegalArgumentException("汪云飞数据已经存在,事物BU回滚");

		}

		return p;
	}

}
